package cn.tedu.finance.service.impl;

import cn.tedu.base.exception.ServiceException;
import cn.tedu.base.response.StatusCode;
import cn.tedu.finance.mapper.PurchaseMapper;
import cn.tedu.finance.pojo.dto.PurchaseQueryParam;
import cn.tedu.finance.pojo.dto.PurchaseSaveParam;
import cn.tedu.finance.pojo.entity.Purchase;
import cn.tedu.finance.pojo.vo.PurchaseVO;
import cn.tedu.finance.service.PurchaseService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Slf4j
@Service
public class PurchaseServiceImpl  implements PurchaseService {
    @Autowired
    private PurchaseMapper purchaseMapper;
    @Override
    public List<PurchaseVO> select(PurchaseQueryParam purchaseQueryParam) {
        log.debug("这是查询数据的第2次出现"+purchaseQueryParam);
        List<PurchaseVO> list = purchaseMapper.select(purchaseQueryParam);
        if (list.size()==0){
            throw new ServiceException(StatusCode.DATA_UNEXISTS);
        }
        log.debug("回去的路----------------------------------------"+list);
        return list;
    }





    @Override
    public void save(PurchaseSaveParam purchaseSaveParam) {
        log.debug("这是保存数据的第二次出现"+purchaseSaveParam);


        purchaseSaveParam.setPurchaseTime(new Date());
        purchaseMapper.save(purchaseSaveParam);
    }
}
